clear all
set more off

**********************************************************************
* DEFINE FEMALE-FOUNDED FIRMS using DADS POST 2006
***********************************************************************
use  "${file}dads2006_light.dta", clear // available on CASD, not provided as pseudo data
unique SIREN
gen Y=2006
replace PCS=lower(PCS)
replace PCS="" if regexm(PCS,"[1-9][0-9][0-9][a-z]")==0
drop if S_BRUT==.

* number of employees
bys SIREN: gen dads_n=_N
bys SIREN SEXE: gen dads_f=N if SEXE=="2" // nb of female employees
bys SIREN: egen max=max(dads_f)
replace dads_f=max/dads_f
drop max

* female-founded defined with ceo-executives occupation
gen pcs2=substr(PCS,1,2)
destring pcs2, replace
gen exe=(pcs2==37|pcs2==38)
gen ceo=(pcs2==23|pcs2==22)
drop if S_BRUT==.
bys SIREN: egen maxceo=max(ceo)
replace ceo=. if maxceo==0
drop maxceo

* female-founded defined with max gross wage
bys SIREN : egen salaire_max=max(S_BRUT)
sort SIREN S_BRUT
gen top_salaire=(salaire_max==S_BRUT)
tab SEXE if top_salaire
tab SEXE if ceo
gsort SIREN -S_BRUT -AGE
by SIREN: gen rank=_n // define wage rank within the firm

* female-founded defined with ceo position if available, if not use top wage
gen sex=SEXE=="2"
tab SEXE top_salaire, cell
tab SEXE ceo, cell
gen ceo_f=ceo*sex
gsort SIREN Y -ceo_f

bys SIREN: replace ceo_f=ceo_f[1] if !missing(ceo_f)
gen top1_f=top_salaire*sex
gsort SIREN Y -top1_f
bys SIREN: replace top1_f=top1_f[1] if !missing(top1_f)

gen female=ceo_f
replace female = top1_f if female==.
tab female

* alternative: use female-founded firms if at least one female among the top 3 or top 5 earners within the firm
gen f=SEXE=="2"
bys SIREN: egen top5_nf=sum(f) if rank<=5
bys SIREN: egen top3_nf=sum(f) if rank<=3
gsort SIREN -top5_nf
by SIREN: replace top5_nf=top5_nf[1]
by SIREN: replace top3_nf=top3_nf[1]
sort SIREN rank

* dimention: cross section of firms and keep the relevant variables
duplicates drop SIREN, force 
keep SIREN dads_n dads_f ceo_f top1_f top5_nf top3_nf female

save "${file}dads2006_pme.dta", replace


**********************************************************************
* TABLE 10 - REGRESSIONS
**********************************************************************
* prepare regression samples
use "${file}pme2010.dta", clear
keep if sous_population=="GAZELLE" // keep gazelles

* merge female-founded firms
merge 1:1 SIREN using  "${file}dads2006_pme.dta" 
keep if _m==3
drop _merge

* define fixed effects
gen APE2=substr(ape08,1,2)
egen ape2=group(APE2)
egen apey2=group(APE2 creation)

* prepare variables variables
//  vc
destring capital2010 capital2007, replace
destring cap2010_caprisq cap2007_caprisq, replace
tab cap2007_caprisq
gen vc= (cap2010_caprisq==1|cap2010_caprisq==2|cap2007_caprisq==1)
tab vc
gen vc_app= (cap2010_caprisq==1|cap2010_caprisq==2|cap2007_caprisq==1|cap2010_caprisq==3)
tab vc_app

// bank
destring pret2010_banque pret2007_banque, replace
gen bank=(pret2010_banque==1|pret2010_banque==2|pret2007_banque==1|pret2007_banque==2)
tab bank
gen bank_app = (pret2010_banque!=.|pret2007_banque!=.)
tab bank_app
gen bank2010=(pret2010_banque==1|pret2010_banque==2)
tab bank2010
gen bank2007=(pret2007_banque==1|pret2007_banque==2)
tab bank2007
gen bank2=1 if pret2010_banque==2|pret2007_banque==2|pret2010_banque==3|pret2007_banque==3
replace bank2=0 if pret2010_banque==1|pret2007_banque==1
gen bankf=bank*female
label var bankf "Female $\times$ Bank loans"
label var bank "Bank loans"
label var female "Female-founded"

* Panel A Regressions - Gender Gap
eststo clear

reghdfe vc female, cluster(ape2) absorb(apey)
estimates store f_1
estadd local year "Yes"
estadd ysumm, mean

reghdfe bank female, cluster(ape2) absorb(apey2)
estimates store f_2
estadd local year "Yes"
estadd ysumm, mean

reghdfe vc female bank bankf , cluster(ape2) absorb(apey2)
estimates store f_3
estadd local year "Yes"
estadd ysumm, mean

reghdfe vc_app female, cluster(ape2) absorb(apey2)
estimates store f_4
estadd local year "Yes"
estadd ysumm, mean

reghdfe bank_app female, cluster(ape2) absorb(apey2)
estimates store f_5
estadd local year "Yes"
estadd ysumm, mean

reghdfe vc_app bank_app##female, cluster(ape2) absorb(apey2)

reghdfe vc_app female bank bankf, cluster(ape2) absorb(apey2)
estimates store f_6
estadd local year "Yes"
estadd ysumm, mean

esttab f_1 f_2 f_3 f_4 f_5 f_6 /*
*/ using "${output}table_pme_aug2024.tex" /*
*/ ,replace booktabs label depvars numbers brackets lines compress nocons /*
*/ cells("b(star fmt(%9.4f))" "se(par fmt(%9.3f))") star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(year r2 N ymean, fmt(0 %9.3fc %9.0fc %9.4fc) /*
*/ labels(`"Sector $\times$ Cohort-year FE"'  `"R^{2}"' `"Observations"' `"Mean dep. var."')) 


* Future financing
destring oufin_avenir_* fina_avenir_*, replace
replace fina_avenir_capi=0 if fina_avenir_capi!=1
replace fina_avenir_pret=0 if fina_avenir_pret!=1
replace oufin_avenir_banqu=0 if oufin_avenir_banqu!=1
replace oufin_avenir_caprisqu=0 if oufin_avenir_caprisqu!=1
replace oufin_avenir_provi=0 if oufin_avenir_provi!=1
replace oufin_avenir_entpub=0 if oufin_avenir_entpub!=1
replace oufin_avenir_pro=0 if oufin_avenir_pro!=1
replace oufin_avenir_fam=0 if oufin_avenir_fam!=1

reghdfe  oufin_avenir_banqu female bank bankf, cluster(ape2) absorb(apey2)
estimates store f_7
estadd local year "Yes"
estadd ysumm, mean
reghdfe  oufin_avenir_caprisqu female bank bankf, cluster(ape2) absorb(apey2)
estimates store f_8
estadd local year "Yes"
estadd ysumm, mean

esttab f_1 f_2 f_3 f_4 f_5 f_6 f_7 f_8 /*
*/ using "${output}table_pme_aug2024.tex" /*
*/ ,replace booktabs label depvars numbers brackets lines compress nocons /*
*/ cells("b(star fmt(%9.4f))" "se(par fmt(%9.3f))") star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(year r2 N ymean, fmt(0 %9.3fc %9.0fc %9.4fc) /*
*/ labels(`"Sector $\times$ Cohort-year FE"'  `"R^{2}"' `"Observations"' `"Mean dep. var."')) 

* Panel B regressions - Guarantees
destring garanti2010_neces garanti2007_neces, replace
gen garanti=0 if garanti2010_neces==2|garanti2007_neces==2 
replace garanti=1 if garanti2010_neces==1|garanti2007_neces==1 
destring garan_*, replace
gen garan_fam=(garan_fam_2010==1|garan_fam_2007==1) 
gen garan_pro=(garan_pro_2010==1|garan_pro_2007==1) 
gen garan_cautcoll=(garan_cautcoll_2010==1|garan_cautcoll_2007==1) 
gen garan_autent=(garan_autent_2010==1|garan_autent_2007==1) 
gen garan_entpub=(garan_entpub_2010==1|garan_entpub_2007==1) 
gen garan_autgar=(garan_autgar_2010==1|garan_autgar_2007==1) 

eststo clear
reghdfe garanti female if bank_app, cluster(ape2) absorb(apey2)
estimates store g_1
estadd local year "Yes"
estadd ysumm, mean

reghdfe garan_pro female if bank_app, cluster(ape2) absorb(apey2)
estimates store g_2
estadd local year "Yes"
estadd ysumm, mean

reghdfe garan_fam female if bank_app, cluster(ape2) absorb(apey2)
estimates store g_3
estadd local year "Yes"
estadd ysumm, mean

reghdfe garan_cautcoll female if bank_app, cluster(ape2) absorb(apey2)
estimates store g_4
estadd local year "Yes"
estadd ysumm, mean

reghdfe garan_entpub female if bank_app, cluster(ape2) absorb(apey2)
estimates store g_5
estadd local year "Yes"
estadd ysumm, mean

reghdfe garan_autgar female if bank_app, cluster(ape2) absorb(apey2)
estimates store g_6
estadd local year "Yes"
estadd ysumm, mean

esttab g_1 g_2 g_3 g_4 g_5 g_6 /*
*/ using "${output}table_pme_garanties_aug2024.tex" /*
*/ ,replace booktabs label depvars numbers brackets lines compress nocons /*
*/ cells("b(star fmt(%9.4f))" "se(par fmt(%9.3f))") star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(year r2 N ymean, fmt(0 %9.3fc %9.0fc %9.4fc) /*
*/ labels(`"Sector $\times$ Cohort-year FE"'  `"R^{2}"' `"Observations"' `"Mean dep. var."')) 


* Panel C - Regressions - why failure to secure bank loans
destring raisonbanqu_*, replace
gen raisonbanqu_poten=(raisonbanqu_poten_2010==1|raisonbanqu_poten_2007==1) 
gen raisonbanqu_dette=(raisonbanqu_dette_2010==1|raisonbanqu_dette_2007==1) 
gen raisonbanqu_histo=(raisonbanqu_histo_2010==1|raisonbanqu_histo_2007==1) 
gen raisonbanqu_cota=(raisonbanqu_cota_2010==1|raisonbanqu_cota_2007==1) 
gen raisonbanqu_capi=(raisonbanqu_capi_2010==1|raisonbanqu_capi_2007==1) 
gen raisonbanqu_rembou=(raisonbanqu_rembou_2010==1|raisonbanqu_rembou_2007==1) 
gen raisonbanqu_pasrais=(raisonbanqu_pasrais_2010==1|raisonbanqu_pasrais_2007==1) 
gen raisonbanqu_garan=(raisonbanqu_garan_2010==1|raisonbanqu_garan_2007==1) 

eststo clear
reghdfe raisonbanqu_cota female if bank_app==1, cluster(ape2) absorb(apey2)
estimates store r_1
estadd local year "Yes"
estadd ysumm, mean
reghdfe raisonbanqu_capi female if bank_app==1, cluster(ape2) absorb(apey2)
estimates store r_2
estadd local year "Yes"
estadd ysumm, mean
reghdfe raisonbanqu_dette female if bank_app==1, cluster(ape2) absorb(apey2)
estimates store r_3
estadd local year "Yes"
estadd ysumm, mean
reghdfe raisonbanqu_garan female if bank_app==1, cluster(ape2) absorb(apey2)
estimates store r_4
estadd local year "Yes"
estadd ysumm, mean
reghdfe raisonbanqu_poten female if bank_app==1, cluster(ape2) absorb(apey2)
estimates store r_5
estadd local year "Yes"
estadd ysumm, mean
reghdfe raisonbanqu_pasrais female if bank_app==1, cluster(ape2) absorb(apey2)
estimates store r_6
estadd local year "Yes"
estadd ysumm, mean

esttab r_1 r_2 r_3 r_4 r_5 r_6 /*
*/ using "${output}table_pme_raisonbank_aug2024.tex" /*
*/ ,replace booktabs label depvars numbers brackets lines compress nocons /*
*/ cells("b(star fmt(%9.4f))" "se(par fmt(%9.3f))") star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(year r2 N ymean, fmt(0 %9.3fc %9.0fc %9.4fc) /*
*/ labels(`"Sector $\times$ Cohort-year FE"'  `"R^{2}"' `"Observations"' `"Mean dep. var."')) 

